<template>
  <div class="notification-deal views-container">
    <div class="wlm-form">
      <div class="wlm-form-header">基础设置</div>
      <div class="wlm-form-content" v-if="$values">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="发送时间点" >
            <div v-if="$route.query.key=='unpaid'">
              <div class="flex-row">
                <span>用户下单</span>
                <el-input style="margin:0 6px;width:100px;" v-model="$values.common.unpaid"></el-input>
                <span>分钟未付款</span>
              </div>
            </div>
            <span v-if="$route.query.key=='ordercheck'">订单核销时 </span>
            <span v-if="$route.query.key=='refund'">退款成功时</span>
            <span v-if="$route.query.key=='pay'">用户付款完成后</span>
            <span v-if="$route.query.key=='selfget'">订单自提时</span>
            <span v-if="$route.query.key=='send'">订单发货时</span>
            <span v-if="$route.query.key=='aftersale'">处理售后时</span>
            <span v-if="$route.query.key=='lottery'">开奖完成时</span>
            <span v-if="$route.query.key=='groups'">拼团成功或者失败后</span>
            <span v-if="$route.query.key=='profit'">分销商下线购买商品下单时</span>
            <span v-if="$route.query.key=='shopextract'">商家提现审核通过时</span>
            <span v-if="$route.query.key=='bargain'">砍价成功或者失败后</span>
            <span v-if="$route.query.key=='adminpay'">用户付款完成后发送给商家管理员和平台管理员</span>
            <span v-if="$route.query.key=='orderOverdue'">核销订单到期时</span>
            <span v-if="$route.query.key=='cgpReminder'">团购订单到货时，提醒用户提货</span>
            <span v-if="$route.query.key=='cgpDelay'">团购订单延期时</span>
            <span v-if="$route.query.key=='reserve'">通知用户预约结果,通知商家管理员审核</span>
             <span v-if="$route.query.key=='luckstart'">通知用户活动已开始</span>
          </el-form-item>
        </el-form>
      </div>
      <!-- <div class="wlm-form-header">短信设置</div>
        <div class="wlm-form-content" v-if="$values">
            <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
                <el-form-item label="模板ID">
                    <el-input v-model="$values.sms.templateid"></el-input>
                    <div class="form-help" v-if="$route.query.newNumber=='1'">模板内容：亲，您购买的{商品名称}还未付款，请尽快付款</div>
                    <div class="form-help" v-if="$route.query.newNumber=='2'">模板内容：亲，你购买的{商品名称}已经核销，请点击查看</div>
                    <div class="form-help" v-if="$route.query.newNumber=='3'">模板内容：亲，你购买的{商品名称}退款成功，请点击查看</div>
                    <div class="form-help" v-if="$route.query.newNumber=='4'">模板内容：亲，你在{店铺名}购买的{商品名称}商品已支付成功。</div>
                    <div class="form-help" v-if="$route.query.newNumber=='5'">模板内容：亲，你购买的{商品名称}已经自提，请点击查看</div>
                    <div class="form-help" v-if="$route.query.newNumber=='6'">模板内容：亲，你购买的{商品名称}已经发货，请点击查看</div>
                    <div class="form-help" v-if="$route.query.newNumber=='7'">模板内容：亲，你申请的售后订单{订单编号}未通过，请联系商家处理</div>
                </el-form-item>
                <el-form-item label="是否开启">
                    <el-radio-group v-model="$values.sms.status">
                        <el-radio label="1">开启</el-radio>
                        <el-radio label="0">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-form-header">微信模板消息</div>
        <div class="wlm-form-content" v-if="$values">
            <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
                <el-form-item label="是否开启">
                    <el-radio-group v-model="$values.wxapp.status">
                        <el-radio label="1">开启</el-radio>
                        <el-radio label="0">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
        </div> -->
     
        <div class="wlm-form-header" v-if="patSetting.channel.wxapp.open &&  $route.query.key !=='cgpReminder'&& $route.query.key !=='cgpDelay'">微信小程序消息</div>
         <div v-if="$route.query.key !='unpaid'">
      <div class="wlm-form-content" v-if="$values&&patSetting.channel.wxapp.open &&  $route.query.key !=='cgpReminder'&& $route.query.key !=='cgpDelay'">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="是否开启">
            <el-radio-group v-model="$values.sapp.status">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="模板ID">
           <div style="display:flex;">
              <el-input placeholder="模板ID" v-model="$values.sapp.template_id">
              <el-button @click="oneGetCode('sapp',2)" slot="append">一键获取</el-button>
            </el-input>
            <div class="form-help" style="margin-left:20px;">注：请在小程序后台 设置=>基础设置=>服务类目中添加“服装/鞋/箱包“</div>
           </div>
          </el-form-item>
        </el-form>
      </div>
     
      </div>
        <div v-else>
         <div class="form-help" style="margin-left:70px;">小程序渠道暂不支持该模版消息 </div>
      </div>
      <div class="wlm-form-header" v-if="patSetting.channel.wechat.open || $route.query.key =='orderOverdue' ||  $route.query.key =='cgpReminder' || $route.query.key =='cgpDelay'">微信公众号消息</div>
      <div class="wlm-form-content" v-if="$values&&patSetting.channel.wechat.open || $route.query.key =='orderOverdue' || $route.query.key =='cgpReminder' || $route.query.key =='cgpDelay'">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="是否开启" v-if="$route.query.key !=='orderOverdue'">
            <el-radio-group v-model="$values.wechat.status">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- 另外两个地方也要加！！ -->
          <!-- <el-form-item label="是否使用独立模板">
                    <el-radio-group v-model="$values.wechat.is_stand">
                        <el-radio label="1">独立</el-radio>
                        <el-radio label="2">默认</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="公众号短信模板" v-show="$values.wechat.is_stand==1">
                    <div class="flex-row">
                        <el-button :type="haswechatName?'':'primary'" @click="$refs.choosewechat.toggle()" style="display: block;">{{haswechatName?haswechatName:'选择公众号短信模板'}}</el-button>
                        <el-button v-if="haswechatName" @click="smsClearwechat" type="text" style="margin-left:20px;" icon="el-icon-delete"></el-button>
                    </div>
                    <choose-sms ref="choosewechat" :config="choosewechatConfig" :changeEvt="filterswechatChange"></choose-sms>
                </el-form-item>
                v-show="$values.wechat.is_stand==2" -->
          <el-form-item label="模板ID">
            <el-input placeholder="模板ID" v-model="$values.wechat.template_id">
              <el-button @click="oneGetCode('wechat',4)" slot="append">一键获取</el-button>
            </el-input>
            <div class="form-help" v-if="$route.query.key=='unpaid'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM401751289[名称：订单待付款提醒]</div>
            <div class="form-help" v-if="$route.query.key=='ordercheck'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM406638019[名称：核销成功提醒]</div>
            <div class="form-help" v-if="$route.query.key=='refund'">公众平台模板消息编号：IT科技—互联网|电子商务—TM00430[名称：退款成功通知]</div>
            <div class="form-help" v-if="$route.query.key=='pay'">公众平台模板消息编号：IT科技—互联网|电子商务—TM00015[名称：订单支付成功]</div>
            <div class="form-help" v-if="$route.query.key=='selfget'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM406638019[名称：核销成功提醒]</div>
            <div class="form-help" v-if="$route.query.key=='send'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM200565259[名称：订单发货提醒]</div>
            <div class="form-help" v-if="$route.query.key=='aftersale'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM415747403[名称：售后状态通知]</div>
            <!-- <div class="form-help" v-if="$route.query.key=='lottery'">公众平台模板消息编号：IT科技—互联网|电子商务—AT0705[名称：开奖结果通知]</div>
                    <div class="form-help" v-if="$route.query.key=='groups'">公众平台模板消息编号：IT科技—互联网|电子商务—AT1814[名称：拼团结果通知]</div>
                    <div class="form-help" v-if="$route.query.key=='profit'">公众平台模板消息编号：IT科技—互联网|电子商务—AT0035[名称：收益到账提现]</div> -->
          </el-form-item>
        </el-form>
      </div>

      <!-- <div class="wlm-form-header" v-if="patSetting.channel.wechat.open || $route.query.key =='orderOverdue' ||  $route.query.key =='cgpReminder' || $route.query.key =='cgpDelay'">微信公众号订阅消息</div>
      <div class="wlm-form-content" v-if="$values&&patSetting.channel.wechat.open || $route.query.key =='orderOverdue' || $route.query.key =='cgpReminder' || $route.query.key =='cgpDelay'">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="是否开启" v-if="$route.query.key !=='orderOverdue'">
            <el-radio-group v-model="$values.new_wechat.status">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="模板ID">
            <el-input placeholder="模板ID" v-model="$values.new_wechat.template_id">
              <el-button @click="oneGetCode('new_wechat',4)" slot="append">一键获取</el-button>
            </el-input>
          </el-form-item>
        </el-form>
      </div> -->


      <div class="wlm-form-header" v-if="patSetting.channel.baiduapp.open && $route.query.key !=='orderOverdue' && $route.query.key !=='cgpReminder' && $route.query.key !=='cgpDelay'">百度小程序消息</div>
      <div class="wlm-form-content" v-if="$values&&patSetting.channel.baiduapp.open && $route.query.key !=='orderOverdue' && $route.query.key !=='cgpReminder' && $route.query.key !=='cgpDelay'">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="是否开启">
            <el-radio-group v-model="$values.baidu.status">
              <el-radio label="1">开启</el-radio>
              <el-radio label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="模板ID">
            <el-input placeholder="模板ID" v-model="$values.baidu.template_id">
              <el-button @click="oneGetCode('baidu',8)" slot="append">一键获取</el-button>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <!-- 在消息通知中点进来之后或在路由上带上可以，根据key可以判短信模版是否显示 -->
      <div class="wlm-form-header" v-if="$route.query.key=='pay' || $route.query.key=='ordercheck' ||  $route.query.key=='send'">短信模板</div>
      <div class="wlm-form-content" v-if="$route.query.key=='pay' || $route.query.key=='ordercheck' ||  $route.query.key=='send'">
        <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
          <el-form-item label="选择短信模板">
            <div class="flex-row">
              <el-button :type="hasSmsName?'':'primary'" @click="$refs.choosesms.toggle()" style="display: block;">{{hasSmsName?hasSmsName:'选择短信模板'}}</el-button>
              <el-button v-if="hasSmsName" @click="smsClear" type="text" style="margin-left:20px;" icon="el-icon-delete"></el-button>
            </div>
            <choose-sms ref="choosesms" :config="choosesmsConfig" :changeEvt="filterssmsChange"></choose-sms>
          </el-form-item>
          <el-form-item label="选择卡密短信模板" v-if="patSetting.plugin.kammi.open && $route.query.key!='ordercheck' && $route.query.key!='send'">
            <div class="flex-row">
              <el-button :type="hasSmsKami?'':'primary'" @click="$refs.chooseKami.toggle()" style="display: block;">{{hasSmsKami?hasSmsKami:'选择卡密短信模板'}}</el-button>
              <el-button v-if="hasSmsKami" @click="smsClearKami" type="text" style="margin-left:20px;" icon="el-icon-delete"></el-button>
            </div>
            <p class="form-help">绑定模板请选择商城变量 '订单类 -> 卡密信息'</p>
            <choose-sms ref="chooseKami" :config="chooseKamiConfig" :changeEvt="filterssmsKami"></choose-sms>
          </el-form-item>
        </el-form>
      </div>
      <!-- <div class="wlm-form-header" v-if="patSetting.channel.aliapp.open">支付宝小程序消息</div>
        <div class="wlm-form-content" v-if="$values&&patSetting.channel.aliapp.open">
            <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="130px" class="retail-form" label-position="right">
                <el-form-item label="是否开启">
                    <el-radio-group v-model="$values.alipay.status">
                        <el-radio label="1">开启</el-radio>
                        <el-radio label="0">关闭</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="模板ID">
                    <el-input placeholder="模板ID" v-model="$values.alipay.template_id"></el-input>
                    <div class="form-help" v-if="$route.query.key=='unpaid'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM401751289[名称：订单待付款提醒]</div>
                    <div class="form-help" v-if="$route.query.key=='ordercheck'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM406638019[名称：核销成功提醒]</div>
                    <div class="form-help" v-if="$route.query.key=='refund'">公众平台模板消息编号：IT科技—互联网|电子商务—TM00430[名称：退款成功通知]</div>
                    <div class="form-help" v-if="$route.query.key=='pay'">公众平台模板消息编号：IT科技—互联网|电子商务—TM00015[名称：订单支付成功]</div>
                    <div class="form-help" v-if="$route.query.key=='selfget'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM406638019[名称：核销成功提醒]</div>
                    <div class="form-help" v-if="$route.query.key=='send'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM200565259[名称：订单发货提醒]</div>
                    <div class="form-help" v-if="$route.query.key=='aftersale'">公众平台模板消息编号：IT科技—互联网|电子商务—OPENTM415747403[名称：售后状态通知]</div>
                </el-form-item>
            </el-form>
        </div> -->
    </div>
    <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
      <el-button size="small" @click="formFormatSubmit({ router: { type: 'replace', path: '/application/notification', code: 1 }})" type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
import {
  smsTplGet,
  smsTplSave,
  createMessageTemplate
} from '@/api/application'
import mixins from '@/mixins/mixins'
import power from '@/mixins/power'
import ChooseSms from '@/components/ChooseSms/index'
export default {
  mixins: [mixins.getters('Form'), power],
  name: 'NotificationDeal',
  components: {
    ChooseSms
  },
  created() {
    // console.log(power, 'power')
  },
  computed: {
    hasSmsName() {
      return this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['name']
    },
    haswechatName() {
      return this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['name']
    },
    hasSmsKami() {
      return this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['name']
    },
    $values() {
      const $valuse = this.formFormatData.formData.values[`${this.$route.query.key}`]
      console.log($valuse, '$valuse')
      const { wechat, baidu, alipay, sms, sms_km,new_wechat} = $valuse
      if (!(!!wechat && Object.keys(wechat)['length'] > 0)) {
        $valuse.wechat = {
          status: '0',
          template_id: ''
        }
      }
      if (!(!!new_wechat && Object.keys(new_wechat)['length'] > 0)) {
        $valuse.new_wechat = {
          status: '0',
          template_id: ''
        }
      }
      if (!!wechat && Object.keys(wechat)['length'] === 2) {
        Object.assign($valuse.wechat, { name: '', templateid: '', is_stand: '2' })
      }
      if (!!new_wechat && Object.keys(new_wechat)['length'] === 2) {
        Object.assign($valuse.new_wechat, { name: '', templateid: '', is_stand: '2' })
      }
      if (!(!!sms && Object.keys(sms)['length'] > 0)) {
        $valuse.sms = {
          name: '',
          templateid: '',
          status: '0',
          template_id: ''
        }
      }
      if (!(!!sms_km && Object.keys(sms_km)['length'] > 0)) {
        $valuse.sms_km = {
          name: '',
          templateid: '',
          status: '0',
          template_id: ''
        }
      }
      if (!(!!baidu && Object.keys(baidu)['length'] > 0)) {
        $valuse.baidu = {
          status: '0',
          template_id: ''
        }
      }
      if (!(!!alipay && Object.keys(alipay)['length'] > 0)) {
        $valuse.alipay = {
          status: '0',
          template_id: ''
        }
      }
      return $valuse
    }
  },
  data() {
    return {
      choosesmsConfig: {
        type: ['choosesms'],
        model: 'display',

        disabled: [{
          label: 'status',
          value: 1,
          reverse: true
        },
        {
          label: 'get_limit_type',
          value: 1
        }, {
          label: 'sms_type',
          value: 40
        }],
        initList: []
      },
      chooseKamiConfig: {
        type: ['choosesms'],
        model: 'display',
        disabled: [{
          label: 'status',
          value: 1,
          reverse: true
        },
        {
          label: 'get_limit_type',
          value: 1
        }, {
          label: 'sms_type',
          value: 40
        }],
        initList: []
      },
      choosewechatConfig: {
        type: ['choosesms'],
        model: 'display',
        wechatFiles: '1',
        disabled: [{
          label: 'status',
          value: 1,
          reverse: true
        },
        {
          label: 'get_limit_type',
          value: 1
        }, {
          label: 'sms_type',
          value: 40
        }],
        initList: []
      },
      formFormatData: {
        key: 'userForm',
        api: {
          editForm: {
            api: smsTplGet,
            params: {
              id: ''
            },
            redirect: 'type'
          },
          submitForm: smsTplSave
        },
        formData: {
          key: this.$route.query.key,
          values: {
            [`${this.$route.query.key}`]: {
              common: {
                unpaid: ''
              },
              // sms: {
              //   status: '0',
              //   templateid: ''
              // },
              new_wechat:{
                status: '0',
                 template_id: '',
              },
              wechat: {
                template_id: '',
                status: '0',
                name: '',
                templateid: '',
                is_stand: '2'
              },
              alipay: {
                status: '0',
                template_id: ''
              },
              baidu: {
                status: '0',
                template_id: ''
              },
              sms: {
                name: '',
                templateid: '',
                template_id: '',
                status: '0'
              },
              sms_km: {
                name: '',
                templateid: '',
                template_id: '',
                status: '0'
              },
              sapp: {
                status: '0',
                template_id: ''
              }
            }
          }
        },
        rules: {
          // name: [{
          //   required: true,
          //   message: '请输入真实姓名',
          //   trigger: 'blur'
          // }],
          // image_id: [{
          //   required: true,
          //   message: '请输入真实姓名',
          //   trigger: 'blur'
          // }],
          // sort: [{
          //   required: true,
          //   message: '请输入真实姓名',
          //   trigger: 'blur'
          // }],
        }
      }
    }
  },
  methods: {
    smsClear() {
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['templateid'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['template_id'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['name'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['status'] = '0'
    },
    filterssmsChange(arg) {
      const { displayData } = arg
      console.log(arg, 'display')
      displayData.map(item => {
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['templateid'] = item.template_id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['template_id'] = item.id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['name'] = item.name
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms']['status'] = '1'
      })
    },
    // kami
    smsClearKami() {
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['templateid'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['template_id'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['name'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['status'] = '0'
    },
    filterssmsKami(arg) {
      const { displayData } = arg
      console.log(displayData, 'display2')
      displayData.map(item => {
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['templateid'] = item.template_id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['template_id'] = item.id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['name'] = item.name
        this.formFormatData.formData.values[`${this.$route.query.key}`]['sms_km']['status'] = '1'
      })
    },
    // 公众号
    smsClearwechat() {
      this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['templateid'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['template_id'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['name'] = ''
      this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['status'] = '0'
    },
    filterswechatChange(arg) {
      const { displayData } = arg
      console.log(displayData, 'display3')
      displayData.map(item => {
        this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['templateid'] = item.template_id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['template_id'] = item.id
        this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['name'] = item.name
        this.formFormatData.formData.values[`${this.$route.query.key}`]['wechat']['status'] = '1'
      })
    },
    oneGetCode(source, sourceNum) {
      //如果是微信公众号订阅消息就走以下流程，不然走原来的流程
      if(source=='new_wechat'){
        createMessageTemplate({ source: sourceNum, key: this.$route.query.key,class:2}).then(res => {
        const { data: { code, data, msg } } = res
        if (code === 1) {
          this.formFormatData.formData.values[`${this.$route.query.key}`][`${source}`] = { status: '1', template_id: data }
          console.log(this.formFormatData.formData.values[`${this.$route.query.key}`][`${source}`])
          this.$message({
            type: 'success',
            message: '获取成功!'
          })
        } else {
          this.$message.error(msg)
        }
      })
      }else{
         createMessageTemplate({ source: sourceNum, key: this.$route.query.key}).then(res => {
        const { data: { code, data, msg } } = res
        if (code === 1) {
          this.formFormatData.formData.values[`${this.$route.query.key}`][`${source}`] = { status: '1', template_id: data }
          console.log(this.formFormatData.formData.values[`${this.$route.query.key}`][`${source}`])
          this.$message({
            type: 'success',
            message: '获取成功!'
          })
        } else {
          this.$message.error(msg)
        }
      })
      }
     
    },
    formFormatCallBack(data, type, response) {
      if (type === 'editBeforeForm') {
        console.log(data)
        const { values: { [`${this.$route.query.key}`]: { wechat, baidu, alipay, sapp, sms, sms_km,new_wechat} } } = data
        if (!(!!wechat && Object.keys(wechat)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].wechat = {
            status: '0',
            template_id: ''
          }
        }
        if (!!wechat && Object.keys(wechat)['length'] === 2) {
          Object.assign(data.values[`${this.$route.query.key}`].wechat, { name: '', templateid: '', is_stand: '2' })
        }
        if (!(!!new_wechat && Object.keys(new_wechat)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].new_wechat = {
            status: '0',
            template_id: ''
          }
        }
        if (!!new_wechat && Object.keys(new_wechat)['length'] === 2) {
          Object.assign(data.values[`${this.$route.query.key}`].new_wechat, { name: '', templateid: '', is_stand: '2' })
        }
        if (!(!!sms && Object.keys(sms)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].sms = {
            name: '',
            templateid: '',
            status: '0',
            template_id: ''
          }
        }
        if (!(!!sms_km && Object.keys(sms_km)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].sms_km = {
            name: '',
            templateid: '',
            status: '0',
            template_id: ''
          }
        }
        if (!(!!baidu && Object.keys(baidu)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].baidu = {
            status: '0',
            template_id: ''
          }
        }
        if (!(!!alipay && Object.keys(alipay)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].alipay = {
            status: '0',
            template_id: ''
          }
        }

        if (!(!!sapp && Object.keys(sapp)['length'] > 0)) {
          data.values[`${this.$route.query.key}`].sapp = {
            status: '0',
            template_id: ''
          }
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.notification-deal {
}
</style>
